package com.hrm.controller;

import com.hrm.dto.ResponseDTO;
import com.hrm.entity.RoomRepair;
import com.hrm.entity.StaffRoom;
import com.hrm.service.RoomRepairService;
import com.hrm.service.StaffRoomService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/room-repair")
public class RoomRepairController {

    @Resource
    private RoomRepairService roomRepairService;

    @ApiOperation("新增")
    @PostMapping
    public ResponseDTO addRepair(@RequestBody RoomRepair roomRepair) {
        return this.roomRepairService.add(roomRepair);
    }

    @ApiOperation("逻辑删除")
    @DeleteMapping("/{id}")
    public ResponseDTO delete(@PathVariable Integer id) {
        return this.roomRepairService.deleteById(id);
    }

    @ApiOperation("批量逻辑删除")
    @DeleteMapping("/batch/{ids}")
    public ResponseDTO deleteBatch(@PathVariable List<Integer> ids) {
        return this.roomRepairService.deleteBatch(ids);
    }

    @ApiOperation("编辑更新")
    @PutMapping
    public ResponseDTO edit(@RequestBody RoomRepair roomRepair) {
        return this.roomRepairService.edit(roomRepair);
    }

    @ApiOperation("查询")
    @GetMapping("/{id}")
    public ResponseDTO findById(@PathVariable Integer id) {
        return this.roomRepairService.findById(id);
    }

    @ApiOperation("分页条件查询")
    @GetMapping
    public ResponseDTO list(@RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size, String roomName) {
        return this.roomRepairService.list(current, size, roomName);
    }

    @ApiOperation("分页")
    @GetMapping("/staff")
    public ResponseDTO findByStaffId(@RequestParam(defaultValue = "1") Integer current, @RequestParam(defaultValue = "10") Integer size, Integer id) {
        return this.roomRepairService.findByStaffId(current, size, id);
    }

    @ApiOperation("数据导出接口")
    @GetMapping("/export")
    public ResponseDTO export(HttpServletResponse response) throws IOException {
        return this.roomRepairService.export(response);
    }

}

